package com.declum.peyar.test.integration;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import com.declum.peyar.PeyarServer;
import com.declum.peyar.client.Peyar;

public class IntegrationTestSuite extends TestCase {
	static boolean serverUpStatus = false;

	public static void startServer() {
		try {
			String[] args = { "-d", "c:\\temp\\", "-p", "54321" };
			PeyarServer.main(args);
			IntegrationTestSuite.serverUpStatus = true;
			System.out.println("Started");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Test suite() {
		Peyar.configure("peyar.declum.com", 54321);
		if (!IntegrationTestSuite.serverUpStatus) {
			IntegrationTestSuite.startServer();
		}

		TestSuite testSuite = new TestSuite(IntegrationTestSuite.class
				.getName());
		testSuite.addTest(PeyarServerIntegrationTest.suite());
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

			@Override
			public void run() {
				PeyarServer.stopServer();
			}
		}));
		return testSuite;
	}
}
